package com.uwo.commons.kits;

import java.util.Collection;

/**
 * 集合工具类
 * @author hao.yan
 */
public class CollectionKits {

    /**
     * 判断集合是否为空
     * @param collection
     * @return
     */
    public static <E> boolean isEmpty(Collection<E> collection){
        return (null == collection || collection.size() == 0);
    }

    /**
     * 全集
     * @param collection0
     * @param collection1
     * @param <E>
     * @return
     */
    public static <E> Collection<E> merge(Collection<E> collection0, Collection<E> collection1){
        collection0.addAll(collection1);
        return collection0;
    }

    /**
     * 交集
     * @param collection0
     * @param collection1
     * @param <E>
     * @return
     */
    public static <E> Collection<E> retain(Collection<E> collection0, Collection<E> collection1){
        collection0.retainAll(collection1);
        return collection0;
    }

    /**
     * 差集
     * @param collection0
     * @param collection1
     * @param <E>
     * @return
     */
    public static <E> Collection<E> difference(Collection<E> collection0, Collection<E> collection1){
        Collection<E> all = merge(collection0, collection1);
        Collection<E> retain = retain(collection0, collection1);
        all.retainAll(retain);
        return all;
    }

}
